package cn.tedu.egaddress1.controller;

import cn.tedu.egaddress1.mapper.AddressMapper;
import cn.tedu.egaddress1.pojo.dto.AddressAddParam;
import cn.tedu.egaddress1.pojo.entiy.Address;
import cn.tedu.egaddress1.pojo.vo.AddressInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @PostMapping("add")
    public String add(@RequestBody AddressAddParam addressAddParam){
        System.out.println("addressAddParam = "+addressAddParam );
        Address address = new Address();
        BeanUtils.copyProperties(addressAddParam,address);
        int i=addressMapper.insertAddress(address);
        if (i>0){
            return "添加地址成功";
        }
        return "添加地址失败";

    }
    @GetMapping("list")
    public List<AddressInfoVO> list(){

        return addressMapper.SelectAddress();
    }
    @PostMapping("del")
    public String del(Integer id){
        System.out.println("id = "+id);
        int i=addressMapper.deleteById(id);
        return "删除地址成功";
    }
}
